//
// File    : Questions.cs
// Author  : Dylan Gleason
// Class   : CST 336 - Junior Project
// Team    : Axial Computing, Inc.
// Project : Uncle Bob
//
// Questions represents a collection of questions to be asked
// on the Application. Questions can be either MultipleChoiceQuestions
// or ExtendedQuestions.
//

using System;
using System.Collections.Generic;
using System.Runtime.Serialization;
using System.ServiceModel;
using System.Web;

namespace UncleBobWebService.Models
{
    [DataContract]
    public class ApplicationQuestions
    {
        [DataMember]
        public Int32 JobID { get; set; }

        // constructor
        public ApplicationQuestions()
        {
            Questions = new List<ApplicationQuestion>();
            CurrentQuestion = 0;
            UserAnswers = false;
        }

        /// <summary>
        /// This is set to true when the questions are all results of User Answers.
        /// </summary>
        [DataMember]
        public bool UserAnswers { get; set; }

        // Questions are reprsented by a List of type ApplicationQuestion
        [DataMember]
        public List<ApplicationQuestion> Questions
        {
            get;
            private set;
        }

        // Total number of questions in the Questions list
        public int TotalQuestions
        {
            get { return Questions.Count; }
        }

        // Index to get the Current Question during application process
        public int CurrentQuestion
        {
            get;
            set;
        }

        // AddQuestion method will add a question to the List of Questions
        public void AddQuestion(ApplicationQuestion question)
        {
            Questions.Add(question);
        }

        public int GetQuestionIndexByQuestionID(int questionID)
        {
            int index = -1;
            foreach (ApplicationQuestion aQ in Questions)
            {
                if (aQ.QuestionID == questionID)
                {
                    index = Questions.IndexOf(aQ);
                }
            }

            return index;
        }

        public ApplicationQuestion GetQuestionByID(int index)
        {
            if (index >= 0 && index < Questions.Count)
                return Questions[index];
            return null;
        }
    }
}

